<template>
  <div>
    <el-form
      :inline="true"
      :model="userForm"
      @keyup.enter.native="getUserList()"
    >
      <el-form-item>
        <el-input
          v-model="userForm.key"
          placeholder="请输入用户名/手机号"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getUserList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="userList"
      border
      v-loading="userListLoading"
      style="width: 100%;"
    >
      <el-table-column
        prop="account"
        header-align="center"
        align="center"
        label="用户名"
      >
      </el-table-column>
      <el-table-column
        prop="name"
        header-align="center"
        align="center"
        label="昵称"
      >
      </el-table-column>
      <el-table-column
        prop="phone"
        header-align="center"
        align="center"
        label="手机号"
      >
      </el-table-column>
      <el-table-column
        prop="email"
        header-align="center"
        align="center"
        label="邮箱"
      >
      </el-table-column>
      <el-table-column
        prop="created"
        header-align="center"
        align="center"
        label="创建时间"
      >
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作"
      >
        <template slot-scope="scope">
          <!-- <el-button v-if="isAuth('sys:role:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.roleId)">修改</el-button>
          <el-button v-if="isAuth('sys:role:delete')" type="text" size="small" @click="deleteHandle(scope.row.roleId)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userForm: {
        key: ''
      },
      userList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      userListLoading: false
    }
  },
  activated() {
    this.getUserList()
  },
  methods: {
    // 获取用户列表
    getUserList() {
      this.userListLoading = true
      this.$http({
        url: this.$http.adornUrl('/member/user/list'),
        method: 'get',
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          key: this.userForm.key
        })
      }).then(({ data }) => {
        console.log(data)
        if (data && data.code === 0) {
          this.userList = data.page.list
          this.totalPage = data.page.totalCount
        } else {
          this.userList = []
          this.totalPage = 0
        }
        this.userListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getUserList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getUserList()
    }
  }
}
</script>
